package com.hzgj.soa.service;

import com.hzgj.bcl.soa.rpc.IpAddress;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Service;

import java.net.UnknownHostException;
import java.util.Random;
import java.util.concurrent.TimeUnit;

/**
 * Created by Administrator on 2016/8/11.
 */
@Service
public class UserServiceImpl implements UserService {

    private Logger logger = LoggerFactory.getLogger(getClass());

    @Override
    public boolean login(User user) {
        logger.info("user {} login in.", user.getName());
        try {
            TimeUnit.MILLISECONDS.sleep(new Random().nextInt(50));
        } catch (InterruptedException e) {
            e.printStackTrace();
        }
        return true;
    }

    @Override
    public boolean logout() {
        return false;
    }

    @Override
    public UserInfo getUserInfo(String userName) {
        try {
            return UserInfo.builder().age(20).height(168).name("marry").sex("male").address(new IpAddress("192.168.0.1", 9090)).build();
        } catch (UnknownHostException e) {
            e.printStackTrace();
        }
        return null;
    }

    @Override
    public void sendFlower(int who) {
//        try {
//            TimeUnit.SECONDS.sleep(3);
//        } catch (InterruptedException e) {
//            e.printStackTrace();
//        }
        System.out.println("handle to me!");
//        throw new RuntimeException("handleMe");
    }
}
